/*---------------< VIET VO >---------------------*/
(function($){
  $.fn.uploadControl=function(options){
	  options=$.extend({
		  file_type: 'jpg|jpeg|gif|bmp|png',
		  path: 'all',
		  language: 'vi',
		  control_link: '/admin/vi/uploadControl',
		  max_depth: 0,
		  buttons:'upload|select|remove|rename|reload|language',
		  callback:{
			  beforeSelect: function(selectedFile,currentControl){},
			  afterSelected: function(selectedFile,currentControl){},
			  onClosed: function(selectedFile,currentControl){}
		  }
	  },options);
	  $(this).each(function(){
		$(this).click(function(){
			VI_UPLOAD_CONTROL.selectedFile='';
			VI_UPLOAD_CONTROL.currentControl = $(this);
			VI_UPLOAD_CONTROL.beforeSelect = options.callback.beforeSelect;
			VI_UPLOAD_CONTROL.afterSelected = options.callback.afterSelected;
			if(options.language == '') options.language = 'vi'; 
			$.fancybox.open({
					href : options.control_link.replace('/vi/','/'+options.language+'/')+'?path='+options.path+'&max_depth='+options.max_depth+'&filter='+options.file_type+'&buttons='+options.buttons,
					type : 'iframe',
					padding : 10,
					title: $(this).attr('title'),
					width: 700,
					height:400,
					helpers: {
						overlay:{
							closeClick : false
						} 
					},
					afterClose: function(){
						options.callback.onClosed(VI_UPLOAD_CONTROL.selectedFile,VI_UPLOAD_CONTROL.currentControl)
					}
				});
		});
	  });
	 
	
  };
})(jQuery);
var VI_UPLOAD_CONTROL = {
		selectedFile: '',
		currentControl: '',
		beforeSelect: function(selectedFile,currentControl){
			
		},
		afterSelected: function(selectedFile,currentControl){
			
		}
}